<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html lang="zh-CN">
   <head>
	 <meta charset="utf-8">
	 <meta http-equiv="X-UA-Compatible" content="IE=edge">
	 <meta name="viewport" content="width=device-width, initial-scale=1">
   </head>
   <body>
	<div class="modal-content">
	  <div class="modal-header">
	    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	    <h4 class="modal-title" id="myModalLabel"><c:if test="${type==1}">新增</c:if><c:if test="${type==2}">编辑</c:if></h4>
	  </div>
	  <div class="modal-body">
	
	    <form id="objectForm" class="form-horizontal" method="post">
	    
	      <div class="form-group">
	        <input type="hidden" name="id" value="${building.id}"/>
	        <input type="hidden" class="typeCode" value="${type}"/>
	        <label for="projectName" class="col-sm-2 control-label"><span style="color:red;"> * </span>所属项目</label>
	        <div class="col-sm-6">
	          <c:if test="${type==2}"><input type="hidden" id="projectEdit" value="${building.sysProject.id}"></c:if>
	          <select class="form-control combox" id="project" name="sysProject[id]"  data-live-search="true">
		         <c:forEach items="${sysProjectList}" var ="project">
		             	 <option value="${project.id}">${project.name}</option>
		         </c:forEach>
		      </select> 
	        </div>
	      </div> 
	      
	      <div class="form-group">
	        <label for="name" class="col-sm-2 control-label"><span style="color:red;"> * </span>名称</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="name" name="name" value="${building.name}">
	        </div>
	      </div> 
	      
	      <div class="form-group">
	        <label for="code" class="col-sm-2 control-label"><span style="color:red;"> * </span>编码</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="code" name="code" value="${building.code}">
	        </div>
	      </div>  
	      
	      <div class="form-group">
	        <label for="longitude" class="col-sm-2 control-label">经度</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="longitude" name="longitude" value="${building.longitude}">
	        </div>
	      </div>   
	      
	      <div class="form-group">
	        <label for="latitude" class="col-sm-2 control-label">纬度</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="latitude" name="latitude" value="${building.latitude}">
	        </div>
	      </div> 
	      
	    </form>
	  </div>
	  <div class="modal-footer">
	  <div class="form-group">
	    <button type="button" class="btn btn-info btn-white btn-round" onclick="objectSubmit();"> <i class="glyphicon glyphicon-ok bigger-125"></i> 确认</button>
	    <button type="button" class="btn btn-default btn-white btn-round" data-dismiss="modal"><i class="glyphicon glyphicon-remove bigger-125"></i> 取消</button>
	  </div>
	  </div>
	</div>
	
	<script>
	var path = "<%=path%>";
	
	$(document).ready(function(){
		//编辑状态下显示已保存的项目
    	   if($(".typeCode").val()==2){
    		   var project = $("#projectEdit").val();
 	       	   $('#project').select2({width:'270px'}).val(project).trigger("change");
    	   }
    });
	
 	 function objectSubmit(){  
 	 	var url= null;
 	 	var type = $('.typeCode').val();
		if(type==1){//添加实体
			url = path + "/buildingController/new";
		}else{//编辑实体
			url = path + "/buildingController/edit";
		}
     	$.ajax({
		  type: "post",
		  url: url,
		  async:false,
		  data: JSON.stringify($('#objectForm').serializeObject()),
		  dataType: "json",
		  contentType:"application/json",  
		  success: function(result){
		         if(result.status){        	 
		        		$.toast({
		        		    text: result.message,
		        		    hideAfter : 1500,  
		        		    stack : 1,  
		        		    showHideTransition: 'slide',
		        		    icon: 'success',
		        		    textAlign : 'center',
		        		    position : 'top-right'
		        		})
		        	   $('#objectForm').parents('.modal').modal('hide');
		        	   $table.bootstrapTable('refresh');
		         }else{
		        	 $.toast({
		        		    text: result.message,
		        		    hideAfter : 1500,  
		        		    stack : 1,  
		        		    showHideTransition: 'slide',
		        		    icon: 'error',
		        		    textAlign : 'center',
		        		    position : 'top-right'
		        		})
		         }
		  }
         });
      } 
	</script>
	</body>
</html>
